package com.qt.vaildator;

import com.qt.exception.StatusFailException;
import com.qt.pojo.dto.SubmitJudgeDTO;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author pgw
 * @version 1.0
 * @description
 * @date Create by 2023/9/25 16:19
 */
@Component
public class JudgeVaildator {

    private final static List<String> HOJ_LANGUAGE_LIST = Arrays.asList(
            "C++", "C++ With O2", "C++ 17", "C++ 17 With O2","C++ 20", "C++ 20 With O2",
            "C", "C With O2", "Python3", "Python2", "Java", "Golang", "C#", "PHP", "PyPy2", "PyPy3",
            "JavaScript Node", "JavaScript V8", "Ruby", "Rust");
    public void validateSubmissionInfo(SubmitJudgeDTO submitJudgeDto) throws StatusFailException {


        if ( !HOJ_LANGUAGE_LIST.contains(submitJudgeDto.getLanguage())) {
            throw new StatusFailException("提交的代码的语言错误！请使用" + HOJ_LANGUAGE_LIST + "中之一的语言！");
        }

        if (submitJudgeDto.getCode().length() < 30) {
            throw new StatusFailException("提交的代码是无效的，代码字符长度请不要低于30！");
        }

        if (submitJudgeDto.getCode().length() > 65535) {
            throw new StatusFailException("提交的代码是无效的，代码字符长度请不要超过65535！");
        }
    }


}
